package com.ruoyi.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jnxx.basic.util.HttpTool;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.domain.TAccount;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/system/xc")
public class ChannelAccountController {

    @GetMapping("/loadList")
    public AjaxResult loadList(){
        HashMap<String, String> map = new HashMap<>();
        String res = HttpTool.sendGet("http://127.0.0.1:8068/api/xc/loadList", map);
        JSONObject parseObject = JSONObject.parseObject(res);
        String code = parseObject.getString("code");
        if (code == null) {
            log.info("获取代理信息失败");
            throw new GlobalException("获取代理信息失败");
        }
        JSONArray data = parseObject.getJSONArray("data");
        return AjaxResult.success(data);
    }


    @GetMapping("/postpaidAgentList")
    public AjaxResult postpaidAgentList(){
        HashMap<String, String> map = new HashMap<>();
        String res = HttpTool.sendGet("http://127.0.0.1:8068/api/xc/postpaidAgentList", map);
        JSONObject parseObject = JSONObject.parseObject(res);
        String code = parseObject.getString("code");
        if (code == null) {
            log.info("获取代理信息失败");
            throw new GlobalException("获取代理信息失败");
        }
        JSONArray data = parseObject.getJSONArray("data");
        return AjaxResult.success(data);
    }

    @GetMapping("/agentStatementList/{agentAccount}")
    public AjaxResult agentStatementList(@PathVariable("agentAccount") String agentAccount){
        HashMap<String, String> map = new HashMap<>();
        String res = HttpTool.sendGet("http://127.0.0.1:8068/api/xc/agentStatementList/"+agentAccount, map);
        JSONObject parseObject = JSONObject.parseObject(res);
        String code = parseObject.getString("code");
        if (code == null) {
            log.info("获取代理账单信息失败");
            throw new GlobalException("获取代理账单信息失败");
        }
        JSONArray data = parseObject.getJSONArray("data");
        return AjaxResult.success(data);
    }



    @GetMapping("/loadProductList")
    public AjaxResult loadProductList(){
        HashMap<String, String> map = new HashMap<>();
        String res = HttpTool.sendGet("http://127.0.0.1:8068/api/xc/loadProductList", map);
        JSONObject parseObject = JSONObject.parseObject(res);
        String code = parseObject.getString("code");
        if (code == null) {
            log.info("获取产品信息失败");
            throw new GlobalException("获取产品信息失败");
        }
        JSONArray data = parseObject.getJSONArray("data");
        return AjaxResult.success(data);
    }



}
